package unipi.helpers;
import java.security.MessageDigest;

public class Hash
{
	
	private static String byteArrayToHexString(byte[] b)
	{
		String result = "";
		for (int i=0; i < b.length; i++)
		{
			result += Integer.toString( ( b[i] & 0xff ) + 0x100, 16).substring(1);
		}
		
		return result;
	}
	
	public static String SHA1(String m)
	{		
		MessageDigest md = null;
		byte[] msg = null;
		
		try
	    {
	   	 msg = m.getBytes("UTF-8");
	   	 md = MessageDigest.getInstance("SHA-1");
	    }
	    catch(Exception e)
	    {
	   	 System.out.println("Exception in hash class : " + e.toString());
	   	 return null;
	    } 
	    
	    return byteArrayToHexString(md.digest(msg));
		
	}
	
}
